 
import org.papervision3d.cameras.Camera3D;
import org.papervision3d.scenes.MovieScene3D;

/**
 * Animates a randomly tweening 3d ribbon  
 * Uses papervision 3D engine: papervision3d.org
 * 
 * by Felix Turner
 * www.airtightinteractive.com
 */

class Main extends MovieClip 
{
	// _______________________________________________________________________
	//                                                                  vars3D
	static private var CAM_SPEED :Number = 60;	
	static private var CAM_RADIUS :Number = 2000;	
	static private var RIBBON_COUNT :Number = 1;	
	
	private var container :MovieClip;
	private var scene     :MovieScene3D;
	private var camera    :Camera3D;	
	private var _camAng:Number;
			
	// _______________________________________________________________________
	//                                                                    Main
	function Main()
	{
		init3D();
		this.onEnterFrame = loop3D;
	}

	// _______________________________________________________________________
	//                                                                  Init3D
	function init3D()
	{
		// Create container movieclip and center it
		container = this.createEmptyMovieClip( "container", this.getNextHighestDepth() );
		container._x = Stage.width/2;
		container._y = Stage.height/2;

		// Create MovieScene for hotspot mode
		// This scene renders each object in a separate movie clip, so you can add events to them easily.
		// This movie clip is called container.
		scene = new MovieScene3D( container);

		// Create camera
		var initObj:Object = new Object;
		
		initObj.sort = false;
		
		camera = new Camera3D(null,null,null,initObj);
		camera.z = -CAM_RADIUS;
		camera.zoom = 1;
		camera.focus = 500;												
		_camAng = 0;
				
		for (var i : Number = 0; i < RIBBON_COUNT; i++) {
			new Ribbon(scene);
		}			
	}

	// _______________________________________________________________________
	//                                                                    Loop
	function loop3D()
	{
		//rotate cam in a circle				
		_camAng += Math.PI/CAM_SPEED;		
		if (_camAng > Math.PI*2) _camAng = 0;		
		camera.x = Math.sin(_camAng)*CAM_RADIUS;
		camera.z = Math.cos(_camAng)*CAM_RADIUS;		
		// Render
		scene.renderCamera( camera );
	}
	
}